//
//  LGSettingItemController.m
//  LoverGo
//
//  Created by YeXiao on 14-5-21.
//  Copyright (c) 2014年 yexiao. All rights reserved.
//

#import "LGUtil.h"
#import "DataCenter.h"
#import "UtilDefine.h"
#import "LGChangeViewController.h"
#import "LGSettingItemController.h"

@implementation LGSettingItemController
-(void)loadView
{
    
    [self dinglan];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(loginNof:) name:userUpDateSPath object:nil];
    _settingView = [[LGSettingView alloc] initWithFrame:[LGUtil getViewFrame]];
    _settingView.tableView.delegate = self;
    _settingView.tableView.dataSource = self;
    [self setView:_settingView];
}
-(id)init{
    self = [super init];
    if (self) {
        self.hidesBottomBarWhenPushed = YES;
    }
    return self;
}
-(void)dinglan{
    UIButton * backBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0,20, 20)];
    [backBtn setBackgroundImage:[UIImage imageNamed:@"btn_back.png"] forState:UIControlStateNormal];
    [backBtn addTarget:self action:@selector(dinglanBackBtn) forControlEvents:UIControlEventTouchUpInside] ;
    [backBtn setShowsTouchWhenHighlighted:YES] ;
    UIBarButtonItem *backbutton = [[UIBarButtonItem alloc]initWithCustomView:backBtn];
    self.navigationItem.leftBarButtonItem = backbutton;
    UILabel *title = [[UILabel alloc]initWithFrame:CGRectMake(90, 0, 140, 30)];
    title.textAlignment = UITextAlignmentCenter;
    title.textColor = LGCOLOR_blue;
    title.text = @"信息修改";
    self.navigationItem.titleView = title;
    
    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"barBG.png"] forBarMetrics:UIBarMetricsDefault];
}
-(void)dinglanBackBtn{
    [self.navigationController popViewControllerAnimated:YES];
}
-(void)viewDidUnload
{
    [[NSNotificationCenter defaultCenter] removeObserver:userUpDateSPath name:nil object:self];
}
-(void)loginNof:(NSNotification *)nof
{
    if ([[nof name] compare:userUpDateSPath] == 0) {
        [self loadView];
    }
    
}
-(void)backLeft
{
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)viewDidLoad
{
    [super viewDidLoad];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 3;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell * cell = [[UITableViewCell alloc] init];
    //点击不要出阴影
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    UserInfo *info = [DataCenter getSingleton].userInfo;
    switch (indexPath.row) {
        case 0:
        {
            UILabel *_textLab = [[UILabel alloc] initWithFrame:CGRectMake(1, 0, 200, 60)];
            if (info !=nil) {
                [_textLab setText:[NSString stringWithFormat:@"姓名:%@",info.userName]];
            }
            [cell addSubview:_textLab];
            break;
        }
        case 1:
        {
            UILabel *_textLab = [[UILabel alloc] initWithFrame:CGRectMake(1, 0, 200, 60)];
            if (info !=nil) {
                NSString *sexStr = @"女";
                if (info.sex == 0){
                    sexStr = @"男";
                }
                [_textLab setText:[NSString stringWithFormat:@"性别:%@",sexStr]];
            }
            [cell addSubview:_textLab];
            break;
        }
        case 2:
        {
            UILabel *_textLab = [[UILabel alloc] initWithFrame:CGRectMake(1, 0, 200, 60)];
            if (info !=nil) {
                [_textLab setText:@"更改密码"];
            }
            [cell addSubview:_textLab];
            break;
        }
        default:
            break;
    }
    return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    return 40;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    LGChangeViewController *vc = [[LGChangeViewController alloc]initWithType:indexPath.row];
    [self.navigationController pushViewController:vc animated:YES];
}
- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [MobClick beginLogPageView:@"信息修改"];
}
- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    [MobClick endLogPageView:@"信息修改"];
}
@end
